<?php
include_once("conexao.php");
mysql_query("SET NAMES 'utf8'",$conexao);
$sql = "select * from estado order by nome";
$result = mysql_query($sql) or die ("Erro: " . mysql_error());

if(mysql_num_rows($result)){
    echo '{"estados":[';

    $first = true;
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
        //  cast results to specific data types

        if($first) {
            $first = false;
        } else {
            echo ',';
        }
        echo json_encode($row);
    }
    echo ']}';
} else {
    echo '[]';
}
?>
